<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Request;

class Goods extends Controller
{
  public function index(){
  	$goods_type=Db::table('goods_type')->select();
  	dump($goods_type);
//  	return view('index',['goods_type'=>$goods_type]);
  }
  public function AddGoods(){
  	$good_type=Db::table('goods_type')->select();
  	return view('AddGoods',['goods_type'=>$good_type]);
  }
  
  public function add(){
  	$input = input();
//	  dump($input);
  	$message=[
  		'goods_name'=>$input['goods_name'],
		'money'=>$input['money'],
		'type_id'=>$input['goods_type'],
		'image'=>$input['ima'],
		'address'=>$input['desc']
	];
  	$goods = Db::table('goods')->insert($message);
//
  	print_r($goods);
  	if($goods=1){
//  		echo 'chengg';
		return ['status'=>true,'message'=>'添加成功'];
	}else{
		return ['status'=>false,'message'=>'添加失败'];
	}
  }
  public function upload(){
  	$image = request()->file('file');
  	$info = $image->move( '../public/static/uploads');
  	$photo_path=$info->getpathName();
  	$update_string=strtr($photo_path,"\\","/");
  	$update_photo = str_replace('../public','',$update_string);
  	return ['image'=>$update_photo];
  }
}
